//
//  EmotionButton.m
//  微博2期
//
//  Created by J on 15/12/16.
//
//

#import "EmotionButton.h"
#import "Emotion.h"
@implementation EmotionButton

//- (instancetype)initWithFrame:(CGRect)frame;//当控件不是从xib storyboad中创建时 xib加载不会调用这个方法


//- (instancetype)initWithCoder:(NSCoder *)aDecoder;//xib加载会调用

//- (void)awakeFromNib;//(对象从文件中解析调用) 先调用 initWithCoder  然后调用  awakeFromNib
//
//
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self =[super initWithCoder:aDecoder] ) {
        [self setUp];
    }
    
    return self;

    
}
//- (instancetype)initWithFrame:(CGRect)frame{
//    
//    if (self = [super initWithFrame:frame]) {
//        NSLog(@"%s",__func__);
//    }
//    
//    return self;
//}
//
//
- (void)awakeFromNib{
    
    [self setUp];
}
    
- (void)setUp{
        
    self.adjustsImageWhenHighlighted = NO;//按钮高亮的时候 不要调整图片(不要调整图片为灰色)
    self.adjustsImageWhenDisabled = NO;
    }

- (void)setEmotion:(Emotion *)emotion{
    _emotion = emotion;
    
    self.titleLabel.font = [UIFont systemFontOfSize:32];
    if (emotion.png) {//如果有图片
        [self setImage:[[UIImage imageNamed:emotion.png]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    }else if (emotion.code)//如没有图片有code
    {    //设置emoji
        [self setTitle:[emotion.code emoji] forState:UIControlStateNormal];
    }

    
}

- (void)setHighlighted:(BOOL)highlighted{
    
     
    
}

@end
